$title Demo model

* ------------------------------------------------------------------------------
* Demonstration model characterizing MPSGE features.
* Laurent Cretegny, CoPS, Monash University, Australia, 2004.
* ------------------------------------------------------------------------------

$if not exist demo.gdx $call gdxxrw i=demo.xls o=demo.gdx index=declare

sets
  s                 sector
  o                 commodity
  f                 primary factor;

parameters
  sam(*,*)          benchmark social accounting matrix
  interm(o,s)       intermediate demand [[intr:o*s]]
  factor(f,s)       factor demand [[fctr:f*s]]
  totfac            total factor demand [[ttfc:]]
  demand(o)         demand for consumption [[dmnd:o]]
  endow(f)          endowment [[endw:f]]
  endowl            endowment of labour [[endl:]]
  endowc            endowment of capital [[endc:]]
  govdem(o)         government demand [[gvdm:o]]
  supply(s,o)       supply of output [[sppl:s*o]]
  etrn(s)           elasticity of transformation [[etrn:s]]
  esub(s)           elasticity of substitution [[esub:s]]
  t_p(o)            tax rate on output [[tp:o]]
  t_pf(f,s)         tax rate on factor [[tpf:f*s]]
  tp_pf(f,s)        power of tax on factor
  upl0              benchmark unemployment index [[upl:]]
  rls0              benchmark employment index [[rls:]];

$gdxin demo
$load s o f etrn esub sam
$gdxin

interm(o,s) = sam(o,s);
factor(f,s) = sam(f,s);
totfac = 110;
demand(o) = sam(o,"ra");
endow(f) = sam("ra",f);
endowl = sam("ra","lab");
endowc = sam("ra","cap");
govdem(o) = sam(o,"gov");
supply(s,o) = sam(s,o) + sam("tya",o)$sameas(s,"s_agr")
              + sam("tyi",o)$sameas(s,"s_ind");
t_pf("lab",s) = sam("tfl",s) / factor("lab",s);
t_pf("cap",s) = sam("tfk",s) / factor("cap",s);
tp_pf(f,s) = 1 + t_pf(f,s);
t_p(o) = 0;
upl0 = 0;
rls0 = 1;

$if not exist demo.har $include gdxtohar

$ontext
$model:demo

$sectors:
  y(s)              ! production
  c                 ! aggregate consumption
  va(s)             ! value added
  g                 ! government expenditure

$commodities:
  p(o)              ! price of commodity
  pc                ! price of aggregate consumption
  pg                ! price of a government output unit
  pva(s)            ! price index for value added
  pf(f)             ! price of primary factor

$consumers:
  ra                ! representative agent income
  gov               ! government income

$auxiliary:
  rls               ! employment index

$prod:y(s)          t:etrn(s)
  o:p(o)            q:supply(s,o)       p:0.8  a:gov  t:0.2     a:gov  t:t_p(o)
  i:p(o)            q:interm(o,s)
  i:pva(s)          q:totfac

$prod:va(s)         s:esub(s)
  o:pva(s)          q:totfac
  i:pf(f)           q:factor(f,s)       p:tp_pf(f,s)        a:gov     t:t_pf(f,s)

$prod:c             s:1.0
  o:pc              q:200
  i:p(o)            q:demand(o)

$prod:g
  o:pg              q:80
  i:p(o)            q:govdem(o)

$demand:ra
  d:pc
  e:pf("lab")       q:endow("lab")      r:rls
  e:pf("cap")       q:endow("cap")

$demand:gov
  d:pg

$constraint:rls
  pf("lab") =g= pc;

$report:
  v:r_supply(s,o)   o:p(o)              prod:y(s)
  v:r_cons(o)       i:p(o)              prod:c

$offtext
$sysinclude mpsgeset demo

* Initial levels on auxiliary variables

rls.l = rls0;

* Benchmark replication

demo.iterlim = 0;
$include demo.gen
solve demo using mcp;
abort$(abs(demo.objval) gt 1e-7) "*** demo does not calibrate ! ***";
demo.iterlim = 1000;

* Fixation of a numeraire to allow comparison

pc.fx = pc.l;

* Counterfactual

t_p(o) = 0.05;
t_pf(f,s) = t_pf(f,s) * 1.05;

$include demo.gen
solve demo using mcp;

* Results

parameters
  res_com           results by commodity in % change from basis
  res_agg           aggregate results in % change from basis; 

res_com("s_agr",o) = (r_supply.l("s_agr",o)/supply("s_agr",o) - 1) * 100;
res_com("s_ind",o) = (r_supply.l("s_ind",o)/supply("s_ind",o) - 1) * 100;
res_com("cons",o) = (r_cons.l(o)/demand(o) - 1) * 100;
res_com("price",o) = (p.l(o) - 1) * 100;

res_agg("c") = (c.l - 1 ) * 100;
res_agg("pc") = (pc.l - 1 ) * 100;
res_agg("employ") = (rls.l - 1 ) * 100;
res_agg("ra_inc") = (ra.l/(sum(o, demand(o))) - 1 ) * 100;

option decimals = 6;
display res_com, res_agg;
